home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / emailm_1 / emailmes.bas next >
Encoding:
BASIC Source File  |  1999-08-18  |  1.5 KB  |  48 lines

  1. Attribute VB_Name = "EmailMessage"
  2. Public Function SendMail(sEmailRecipient As String, sEmailSubject As String, sEmailBody As String)
  3.  
  4. '-----Send an Email Message using Outlook 98-----
  5.  
  6. 'Developers Note:  In References, the Microsoft Outlook 98 Object Model must be selected for this to work
  7. '                  Actual file is MSOUTL85.OLB
  8.  
  9. Dim emailOutlookApp As Outlook.Application
  10. Dim emailNameSpace As Outlook.NameSpace
  11. Dim emailFolder As Outlook.MAPIFolder
  12. Dim emailItem As Outlook.MailItem
  13. Dim EmailRecipient As Recipient
  14.  
  15. '-----Open Outlook in a background process and the Inbox Folder-----
  16. Set emailOutlookApp = CreateObject("Outlook.Application.8")
  17. Set emailNameSpace = emailOutlookApp.GetNamespace("MAPI")
  18. Set emailFolder = emailNameSpace.GetDefaultFolder(olFolderInbox)
  19.  
  20. 'Enable the next line to actually see Outlook Open
  21. 'emailFolder.Display
  22.  
  23. '-----Create a new mail message, set the recipient, subject, and body-----
  24. Set emailItem = emailOutlookApp.CreateItem(olMailItem)
  25. Set EmailRecipient = emailItem.Recipients.Add(sEmailRecipient)
  26. emailItem.Subject = sEmailSubject
  27. emailItem.Body = sEmailBody
  28.  
  29. '-----Send the Email-----
  30. emailItem.Save
  31. emailItem.Send
  32.  
  33. '-----Close the Outlook Application------
  34. emailOutlookApp.Quit
  35.  
  36. '----Inform User of Success-----
  37. MsgBox "Email was sent.", vbInformation
  38.  
  39. '-----Clear out the memory space held by variables-----
  40. 'Usually unnecessary but a good practice
  41.  
  42. Set emailNameSpace = Nothing
  43. Set emailFolder = Nothing
  44. Set emailItem = Nothing
  45. Set emailOutlookApp = Nothing
  46.  
  47. End Function
  48.